/*
    This source file is part of GeNa project.
    Copyright © GeNa project 2008
    For the latest info, see http://code.google.com/p/genaproject/ or  http://lumpyproject.forums-rpg.com

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    Foobar is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with Foobar.  If not, see <http://www.gnu.org/licenses/>. */

#ifndef WINDOWS_FACTORY_H_INCLUDED
#define WINDOWS_FACTORY_H_INCLUDED

#include <map>

#include "managed_window.h"
#include "singleton.h"
#include "view_window.h"
#include "editor_window.h"

class WindowsFactory
{

public:

    template<class Archive> void saveWindow( ManagedWindow* wnd, Archive *ar)
    {
        if( wnd->getName() == "UnknowWindow")
            (dynamic_cast<UnknowWindow*>(wnd))->saveWindow(ar);
        if( wnd->getName() == "ViewWindow")
            (dynamic_cast<ViewWindow*>(wnd))->saveWindow(ar);
        if( wnd->getName() == "EditorWindow")
            (dynamic_cast<EditorWindow*>(wnd))->saveWindow(ar);
    }

    template<class Archive> ManagedWindow* callWindow( std::string name, wxWindow* parent, Archive *ar)
    {
        if( name == "UnknowWindow")
            return UnknowWindow::createWindow(parent, ar);
        if( name == "ViewWindow")
            return ViewWindow::createWindow(parent, ar);
        if( name == "EditorWindow")
            return EditorWindow::createWindow(parent, ar);
        return NULL;
    }

    template<class Archive> ManagedWindow* createWindow(std::string name, wxWindow* parent, Archive *ar)
    {
        ManagedWindow* m = callWindow(name, parent, ar);

        if( m)
        {
            wxSize s = m->getWindow()->GetMinSize();
            s.IncTo(wxSize(20,20));
            m->getWindow()->SetMinSize(s);
        }
        return m;
    }

private:
    WindowsFactory()
    {
    }
    ~WindowsFactory() { }
    MAKE_SINGLETON_NO_CTOR_DTOR(WindowsFactory);
};

#define WindowsFactoryInstance MAKE_SINGLETON_PSEUDO_INSTANCE(WindowsFactory)

#endif // WINDOWS_FACTORY_H_INCLUDED
